package org.example.supermarketms.controller;


import org.example.supermarketms.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/data")
public class DataController {

    @Autowired
    private DataService dataService;

    @GetMapping("/monthly-sales")
    public Map<String, Double> getMonthlySales() throws Exception {
        return dataService.monthlySales();
    }

    @GetMapping("/vegetables")
    public Map<String, Integer> getMonthlyVegetableSales() throws Exception {
        return dataService.monthlyVegetableSales();
    }

    @GetMapping("/payment-methods")
    public Map<String, Long> getPaymentMethodCounts() throws Exception {
        return dataService.paymentMethodCount();
    }

    @GetMapping("/top-discounts")
    public List<Map.Entry<String, Double>> getTopDiscounts() throws Exception {
        return dataService.topFiveDiscountedProducts();
    }

    @GetMapping("/top-products")
    public List<Map.Entry<String, Integer>> getTopSoldProducts() throws Exception {
        return dataService.topFiveSoldProducts();
    }

    @GetMapping("/categories")
    public Map<String, Integer> getCategorySales() throws Exception {
        return dataService.categorySales();
    }
}